# -- coding: utf-8 --
from pprint import pprint

from tools.Request_General import BaseAPI


class ClickhouseDataTable(BaseAPI):
    """数据表组件for clickhouse"""

    def save_edit_datatable(self, payload):
        """数据表新建&编辑（前端调用）"""
        r = self.request_send(json=payload)
        return r

    def save_datatable(self, payload):
        """数据表新建&编辑（后端调用）"""
        r = self.request_send(json=payload)
        return r

    def generate_actual_tablename(self, payload):
        """根据tableName生成实际物理表名"""
        r = self.request_send(json=payload)
        return r

    def table_info_field(self, payload):
        """获取数据表元素信息（从平台获取信息)"""
        r = self.request_send(json=payload)
        return r

    def only_check(self, payload):
        """数据表编辑--仅校验（后端组件调用）"""
        r = self.request_send(json=payload)
        return r

    def delete_datatable(self, payload):
        """只删除物理表"""
        r = self.request_send(json=payload)
        return r

    def get_actual_tablename(self, payload):
        """获取数据表实际表名"""
        r = self.request_send(json=payload)
        return r

    def batch_actual_tablename(self, payload):
        """根据元素名称批量获取实际表名"""
        r = self.request_send(json=payload)
        return r

    def get_datatable_columnInfo(self, payload):
        """根据列名获取数据表的Column信息"""
        r = self.request_send(json=payload)
        return r

    def custom_sql_execute(self, payload):
        """自定义SQL执行(后端调用)--增删改查，支持多表联合查询"""
        r = self.request_send(json=payload)
        return r

    def data_diff(self, payload):
        """判断数据表组件元素配置信息和实际物理数据表字段信息是否一致"""
        r = self.request_send(json=payload)
        return r

    def delete_data(self, payload):
        """删除数据表的数据"""
        r = self.request_send(json=payload)
        return r

    def distinct_column_members(self, payload):
        """查询数据表成员个数"""
        r = self.request_send(json=payload)
        return r

    def get_data_execute_sql(self, payload):
        """执行查询sql查询数据表的数据"""
        r = self.request_send(json=payload)
        return r

    def insert_data(self, payload):
        """向数据表中写入数据"""
        r = self.request_send(json=payload)
        return r

    def insert_ck_data(self, payload):
        """向ck数据表中写入数据"""
        r = self.request_send(json=payload)
        return r

    def table_ifexists(self, payload):
        """根据数据表名称判断数据表是否存在"""
        r = self.request_send(json=payload)
        return r

    def table_info_field_physical(self, payload):
        """获取数据表元素信息（从物理表获取信息）"""
        r = self.request_send(json=payload)
        return r

    def get_datatable_column_list(self, payload):
        """根据实际表名，查询数据表字段信息"""
        r = self.request_send(data=payload)
        return r

    def update_data(self, payload):
        """更新数据表中的数据"""
        r = self.request_send(json=payload)
        return r

    def customize_sql(self, payload):
        """数据表使用视图-自定义sql查询"""
        r = self.request_send(json=payload)
        return r

    def get_using_view_data(self, payload):
        """数据表使用视图获取数据"""
        r = self.request_send(json=payload)
        return r

    def export_table_element(self, payload):
        """元素导出"""
        r = self.request_send(params=payload)
        return r

    def import_table_element(self, payload):
        """元素导入"""
        r = self.request_send(json=payload)
        return r

    def copy_table_element(self, payload):
        """元素复制(单条复制)"""
        r = self.request_send(json=payload)
        return r

    def init_dimension(self, payload):
        """初始化维度表"""
        r = self.request_send(data=payload)
        return r

    def sync_dimension(self, payload):
        """同步维度到ck"""
        r = self.request_send(json=payload)
        return r


if __name__ == '__main__':
    pass
    # from application.general_create import COOKIE, APP_ID, SPACE_ID
    #
    # headers = {"cookie": COOKIE, "language": "zh-cn", "app": APP_ID, "space": SPACE_ID}
    # r = ClickhouseDataTable(version="1.0", headers=headers).customize_sql(
    #     {'elementName': 'app_TestClickhouse_table', 'folderId': '0', 'pageNum': 1, 'showNum': 20,
    #      'sql': "select parent_name FROM ahbrqy004_testClickhouse_1234 where 1=1;select parent_name FROM ahbrqy004_testClickhouse_1234 where 1=1"})
    # pprint(r.json())
